﻿using System;
using System.Collections.Generic;
using System.Data;
using Ledict.ConditionExtract.Model;

namespace Ledict.ConditionExtract.BLL.WorkProcess
{
    public class WorkThread_Public
    {
        //TreeDataBLL trbll = new TreeDataBLL();
        Express_WordBLL wordbll = new Express_WordBLL();
        //ExpressGroupSituationBLL expresitu = new ExpressGroupSituationBLL();

        //AboutRegexBLL aboutreg = new AboutRegexBLL();
        ProcessDataSourceBLL datas = new ProcessDataSourceBLL();
        RegexParse.RegexParse getregex = new RegexParse.RegexParse();
        CaseCauseBLL casecausebLL = new CaseCauseBLL();
        Express_MatchSituationBLL MatchSituationbll = new Express_MatchSituationBLL();
        //WordBankKeyWordsBLL wordbankkeywordsbll = new WordBankKeyWordsBLL();
        NewIDBLL newid = new NewIDBLL();
        Express_WordBankRelBLL express_wordbankrelbll = new Express_WordBankRelBLL();

        public string ErrorRegex = "";//报错正则

        /// <summary>
        /// 隐私处理
        /// </summary>
        /// <param name="paragraphText">段</param>
        /// <param name="caseId">案例ID</param>
        /// <returns>返回结果</returns>
        public string Privacy(string paragraphText, string caseId)
        {
            #region 隐私处理
            //ParagraphText = "被告人谢荣兵已经着手实施盗窃犯罪，由于意志以外的原因而未得逞，系犯罪未遂。";
            //CaseId = "1000249";
            try
            {
                string fields = datas.ExceptAdditionalFields(caseId).Replace("，", ",");
                fields = fields.Replace(",", "|").Replace("，", "|").Replace("*", @"\*").Trim();//取人名
                if (fields != "")
                {
                    paragraphText = System.Text.RegularExpressions.Regex.Replace(paragraphText, fields, "×××");//挖空人名
                }
                //ParagraphText = getregex.GetParseValue("CC1508221657230001", ParagraphText);//排除金额，多×××
                // ParagraphText=getregex.GetParseValue("CC1508211030520001", ParagraphText);//排除某些字符
                return paragraphText;//排除某些字符

            }
            catch (Exception error)
            {
                error.ToString();
                return paragraphText;
            }

            #endregion
        }

        /// <summary>
        /// 节点是否刑事
        /// </summary>
        /// <param name="ccId">节点ID</param>
        /// <param name="type">类型</param>
        /// <returns>结果</returns>
        public bool IsCriminal(string ccId, string type = "1000")
        {
            TreeDataBLL allparent = new TreeDataBLL();
            if (allparent.GetAllParentNode(ccId).Contains(type))//刑事
            {
                return true;
            }
            return false;
        }


        #region 入库

        /// <summary>
        /// 添加表述
        /// </summary>
        /// <param name="resultText">文本</param>
        /// <param name="caseid">案例ID</param>
        /// <param name="paragraphId">逻辑段类型</param>
        /// <param name="causeGroupId">情形分组ID</param>
        /// <param name="ccIdList">组合情形ID</param>
        public string AddToExpress(string resultText, string caseid, string paragraphId, string causeGroupId, string ccIdList, params bool[] isAdd)
        {
            #region 添加match表

            #region 节点属性
            bool ismatchb = getregex.IsMatch("3F53BB8A-08CC-4F55-89A9-8EAAE4FC3163", resultText);//true 不构成
            int ismatch = ismatchb ? 0 : 1; 
            bool affirmIdeaResultb = getregex.IsMatch("EI1601201151020001", resultText);//true 不予认定
            string affirmIdeaResult = affirmIdeaResultb ? "2" : "1";
            SYS_Express_MatchSituation stiuModel = new SYS_Express_MatchSituation();
            stiuModel.IsMatch = ismatch;
            stiuModel.MatchSource = "0";
            stiuModel.AffirmIdeaResult = affirmIdeaResult;
            stiuModel.AffirmIdeaSource = "0";
            #endregion

            string MS_ID = "";
            //组合情形

            string[] situationIDa = ccIdList.Split(',');

            if (situationIDa.Length == 1)
            {
                MS_ID = AddSingleMatch(situationIDa[0], causeGroupId, situationIDa[0], causeGroupId, stiuModel, "-1", true);//从0开始
            }
            else if (situationIDa.Length > 1)
            {
                string allCombinePid = situationIDa[0];
                string allMsIdPid = "";

                MS_ID = AddMatch(situationIDa[0], causeGroupId, allCombinePid, causeGroupId, stiuModel, allMsIdPid, true);//从0开始
                for (int i = 1; i < situationIDa.Length; i++)
                {
                    allCombinePid = allCombinePid + "," + situationIDa[i];
                    if (allMsIdPid != "")
                        allMsIdPid += "," + MS_ID;
                    else
                        allMsIdPid += MS_ID;

                    MS_ID = AddMatch(situationIDa[i], MS_ID, allCombinePid, causeGroupId, stiuModel, allMsIdPid, true);
                }
            }
            #endregion

            #region 添加文本


            SYS_Express_Word WordModel = new SYS_Express_Word();
            WordModel.MS_ID = MS_ID;

            WordModel.EW_CaseId = caseid;
            WordModel.EW_Content = resultText;

            WordModel.EW_UseCount = 1;
            WordModel.EW_WordCount = resultText.Length;
            WordModel.ParagraphTypeId = Convert.ToInt32(paragraphId);
            if (situationIDa.Length == 1) WordModel.EW_IsSingleExpress = 1;
            else WordModel.EW_IsSingleExpress = 0;

            WordModel.EW_ID = wordbll.Exists_WordProcess(WordModel);

            if (WordModel.EW_ID == "")
            {
                WordModel.EW_ID = newid.JudgeDoc_CreateID("SYS_Express_Word");
                if (isAdd.Length > 0 && isAdd[0].ToString() == "True")
                {
                    WordModel.EW_Right = 1;
                }
                else
                {
                    WordModel.EW_Right = 0;
                }
                WordModel.EW_Wrong = 0;
                wordbll.AddWord_Process(WordModel);
            }
            else
            {
                wordbll.UpdateWord_Process(WordModel);
            }
            #endregion

            #region 词库
            List<string> EW_AddElementStr = express_wordbankrelbll.WordBank("", WordModel.EW_Content);

            foreach (var item in EW_AddElementStr)
            {
                if (!express_wordbankrelbll.Exists(WordModel.EW_ID, item))
                {
                    express_wordbankrelbll.Add_Express_WordBankRel(newid.JudgeDoc_CreateID("SYS_Express_WordBankRel"), WordModel.EW_ID, item);
                }
            }
            #endregion
            return WordModel.EW_ID;
        }
        /// <summary>
        /// 添加match表
        /// </summary>
        /// <param name="stiuid">情形ID</param>
        /// <param name="parentId">上一级matchID</param>
        /// <param name="allStituationIDs">所有的情形ID</param>
        /// <param name="causeGroupId">情节分组ID</param>
        /// <param name="stiuModel"></param>
        /// <param name="allParentId">所有的matchID</param>
        /// <param name="isDisplayMatch">是否显示构成不构成，默认不显示，刑事案例才有构成不构成</param>
        public string AddMatch(string stiuid, string parentId, string allStituationIDs, string causeGroupId, SYS_Express_MatchSituation stiuModel, string allParentId, bool isDisplayMatch = false)
        {
            #region 名称暂时不加
            //string NameAdd = "（";

            ////是否显示构成不构成（刑事案例用） todo by zhangpeng 2017-01-04 新需求
            //if (isDisplayMatch)
            //{
            //    if (stiuModel.IsMatch == 1)
            //    { NameAdd += "构成"; }
            //    else { NameAdd += "不构成"; }
            //    if (stiuModel.AffirmIdeaResult == "2")
            //    { NameAdd += ",不认定"; }
            //    else { NameAdd += ",认定"; }
            //}
            //else
            //{
            //    if (stiuModel.AffirmIdeaResult == "2")
            //    { NameAdd += "不认定"; }
            //    else { NameAdd += "认定"; }

            //}
            //NameAdd += "）"; 
            #endregion


            string msId = MatchSituationbll.Exists_MatchSituation(stiuid, stiuModel.IsMatch, stiuModel.MatchSource, stiuModel.AffirmIdeaResult, stiuModel.AffirmIdeaSource, allStituationIDs, parentId, allParentId);//存在
            if (msId == "")
            {
                stiuModel.MS_ID = newid.JudgeDoc_CreateID("SYS_Express_MatchSituation");//Guid.NewGuid().ToString();
                msId = stiuModel.MS_ID;
                stiuModel.SituationID = stiuid;
                SYS_CaseCause dtStiuid = casecausebLL.GetCaseCauseByCCID(stiuid);
                stiuModel.SituationType = dtStiuid.CC_NodeType;
                stiuModel.SituationName = dtStiuid.CC_Name;//+ NameAdd
                stiuModel.ParentID = parentId;
                stiuModel.AllStituationIDs = allStituationIDs;
                if (allParentId == "")
                    stiuModel.AllParentID = stiuModel.MS_ID;
                else
                    stiuModel.AllParentID = allParentId + "," + stiuModel.MS_ID;
                stiuModel.CauseGroupID = causeGroupId;
                stiuModel.CC_IsShowExpress = 0;                
                MatchSituationbll.AddMatchSituation(stiuModel);//添加
            }
            return msId;

        }

        /// <summary>
        /// 添加match表
        /// </summary>
        /// <param name="stiuid">情形ID</param>
        /// <param name="parentId">上一级matchID</param>
        /// <param name="allStituationIDs">所有的情形ID</param>
        /// <param name="causeGroupId">情节分组ID</param>
        /// <param name="stiuModel"></param>
        /// <param name="allParentId">所有的matchID</param>
        /// <param name="isDisplayMatch">是否显示构成不构成，默认不显示，刑事案例才有构成不构成</param>
        public string AddMatchNew(string stiuid, string parentId, string allStituationIDs, string causeGroupId, ref SYS_Express_MatchSituation stiuModel, string allParentId, bool isDisplayMatch = false)
        {
            string NameAdd = "（";
            //是否显示构成不构成（刑事案例用） todo by zhangpeng 2017-01-04 新需求
            if (isDisplayMatch)
            {
                if (stiuModel.IsMatch == 1)
                { NameAdd += "构成"; }
                else { NameAdd += "不构成"; }
                if (stiuModel.AffirmIdeaResult == "2")
                { NameAdd += ",不认定"; }
                else { NameAdd += ",认定"; }
            }
            else
            {
                if (stiuModel.AffirmIdeaResult == "2")
                { NameAdd += "不认定"; }
                else { NameAdd += "认定"; }

            }
            NameAdd += "）";

            string msId = MatchSituationbll.Exists_MatchSituation(stiuid, stiuModel.IsMatch, stiuModel.MatchSource, stiuModel.AffirmIdeaResult, stiuModel.AffirmIdeaSource, allStituationIDs,parentId,allParentId);//存在
            if (msId == "")
            {
                stiuModel.MS_ID = Guid.NewGuid().ToString();
                msId = stiuModel.MS_ID;
                stiuModel.SituationID = stiuid;
                DataTable dtStiuid = casecausebLL.GetSYS_CaseCauseByCCID(stiuid);
                stiuModel.SituationType = Convert.ToInt32(dtStiuid.Rows[0]["CC_NodeType"]);
                stiuModel.SituationName = dtStiuid.Rows[0]["CC_Name"] + NameAdd;
                stiuModel.ParentID = parentId;
                stiuModel.AllStituationIDs = allStituationIDs;
                if (allParentId == "")
                    stiuModel.AllParentID = stiuModel.MS_ID;
                else
                    stiuModel.AllParentID = allParentId + "," + stiuModel.MS_ID;
                stiuModel.CauseGroupID = causeGroupId;
                stiuModel.CC_IsShowExpress = 0;
            }
            else
            {

            }
            return msId;

        }
        /// <summary>
        /// 添加单一表述节点 2017-07-13 ljj 修改
        /// </summary>
        /// <param name="stiuid"></param>
        /// <param name="parentId"></param>
        /// <param name="allStituationIDs"></param>
        /// <param name="causeGroupId"></param>
        /// <param name="stiuModel"></param>
        /// <param name="allParentId"></param>
        /// <param name="isDisplayMatch"></param>
        /// <returns></returns>
        public string AddSingleMatch(string stiuid, string parentId, string allStituationIDs, string causeGroupId, SYS_Express_MatchSituation stiuModel, string allParentId, bool isDisplayMatch = false)
        {
            //Exists_MatchSingleSituation1(int IsMatch, string AffirmIdeaResult, string stiuid)
            string msId = MatchSituationbll.Exists_MatchSingleSituation1(stiuModel.IsMatch,stiuModel.AffirmIdeaResult,stiuid);//存在
            if (msId == "")
            {
                
                stiuModel.MS_ID = newid.JudgeDoc_CreateID("SYS_Express_MatchSituation"); ;
                msId = stiuModel.MS_ID;
                stiuModel.SituationID = stiuid;
                DataTable dtStiuid = casecausebLL.GetSYS_CaseCauseByCCID(stiuid);
                stiuModel.SituationType = Convert.ToInt32(dtStiuid.Rows[0]["CC_NodeType"]);
                stiuModel.SituationName = dtStiuid.Rows[0]["CC_Name"].ToString();
                stiuModel.ParentID = parentId;
                stiuModel.AllStituationIDs = allStituationIDs;
                stiuModel.AllParentID = allParentId;
                stiuModel.CauseGroupID = causeGroupId;
                stiuModel.CC_IsShowExpress = 0;

                MatchSituationbll.AddMatchSituation(stiuModel);//添加
            }
            return msId;

        }


        /// <summary>
        /// 添加单一表述节点 (民事数据处理新)
        /// </summary>
        /// <param name="stiuid"></param>
        /// <param name="parentId"></param>
        /// <param name="allStituationIDs"></param>
        /// <param name="causeGroupId"></param>
        /// <param name="stiuModel"></param>
        /// <param name="allParentId"></param>
        /// <param name="isDisplayMatch"></param>
        /// <returns></returns>
        public string AddSingleMatch1(DataRow dr, string stiuid, string allStituationIDs, SYS_Express_MatchSituation stiuModel, string allParentId,string parentId)
        {
            string nameAdd = "（";
            if (stiuModel.AffirmIdeaResult == "2")
            { nameAdd += "不认定"; }
            else { nameAdd += "认定"; }
            nameAdd += "）";
            string msId = MatchSituationbll.Exists_MatchSingleSituation1(stiuModel.IsMatch,stiuModel.AffirmIdeaResult, stiuid);//存在
            if (msId == "")
            {
                stiuModel.MS_ID = newid.JudgeDoc_CreateID("SYS_Express_MatchSituation"); 
                msId = stiuModel.MS_ID;
                stiuModel.SituationID = stiuid;
                stiuModel.SituationType = Convert.ToInt32(dr["CC_NodeType"].ToString());
                stiuModel.SituationName = dr["CC_Name"].ToString() +nameAdd;
                stiuModel.ParentID = parentId; 
                stiuModel.AllStituationIDs = allStituationIDs;
                stiuModel.AllParentID = allParentId;
                stiuModel.CauseGroupID = dr["CC_ParentID"].ToString();
                stiuModel.CC_IsShowExpress = 0;

                MatchSituationbll.AddMatchSituation(stiuModel);//添加
            }
            return msId;

        }


        /// <summary>
        /// 添加组合表述节点 (民事数据处理新)
        /// </summary>
        /// <param name="stiuid">情形ID</param>
        /// <param name="stiuidName">组合名称</param>
        /// <param name="parentId">上一级matchID</param>
        /// <param name="allStituationIDs">所有的情形ID</param>
        /// <param name="causeGroupId">情节分组ID</param>
        /// <param name="stiuModel"></param>
        /// <param name="allParentId">所有的matchID</param>
        public string AddCivilMatch1(DataRow dr, string stiuid, string allStituationIDs, SYS_Express_MatchSituation stiuModel, string allParentId,string parentId)
        {
            string nameAdd = "（";
            if (stiuModel.AffirmIdeaResult == "2")
            { nameAdd += "不认定"; }
            else { nameAdd += "认定"; }
            nameAdd += "）";
            //if (parentId.StartsWith("S") || parentId.StartsWith("M"))
            //{
            //    stiuModel.ParentID = parentId;
            //}
            //else
            //{
                stiuModel.ParentID = parentId;
            //}
            string msId = MatchSituationbll.Exists_MatchSituation(stiuid, stiuModel.IsMatch, stiuModel.MatchSource, stiuModel.AffirmIdeaResult, stiuModel.AffirmIdeaSource, allStituationIDs, stiuModel.ParentID, 0);//存在
            if (msId == "")
            {
                stiuModel.MS_ID = newid.JudgeDoc_CreateID("SYS_Express_MatchSituation");
                msId = stiuModel.MS_ID;
                stiuModel.SituationID = stiuid;
                stiuModel.SituationType = Convert.ToInt32(dr["CC_NodeType"].ToString());
                //stiuModel.SituationName = dtStiuid.Rows[0]["CC_Name"] + nameAdd;
                stiuModel.SituationName = dr["CC_Name"].ToString() + nameAdd;

                //if (parentId.StartsWith("S") || parentId.StartsWith("M"))
                //{
                //    stiuModel.ParentID = parentId;
                //}
                //else
                //{
                //    stiuModel.ParentID = dr["CC_ParentID"].ToString();
                //}
                stiuModel.AllStituationIDs = allStituationIDs;
                if (allParentId == "")
                    stiuModel.AllParentID = stiuModel.MS_ID;
                else
                    stiuModel.AllParentID = allParentId + "," + stiuModel.MS_ID;
                stiuModel.CauseGroupID = dr["CC_ParentID"].ToString();
                stiuModel.CC_IsShowExpress =0;
                MatchSituationbll.AddMatchSituation(stiuModel);//添加
            }
            return msId;

        }


        /// <summary>
        /// 添加民事match表（组合用）
        /// </summary>
        /// <param name="stiuid">情形ID</param>
        /// <param name="stiuidName">组合名称</param>
        /// <param name="parentId">上一级matchID</param>
        /// <param name="allStituationIDs">所有的情形ID</param>
        /// <param name="causeGroupId">情节分组ID</param>
        /// <param name="stiuModel"></param>
        /// <param name="allParentId">所有的matchID</param>
        public string AddCivilMatch(string stiuid, string stiuidName, string parentId, string allStituationIDs, string causeGroupId, SYS_Express_MatchSituation stiuModel, string allParentId)
        {
            string nameAdd = "（";
            if (stiuModel.AffirmIdeaResult == "2")
            { nameAdd += "不认定"; }
            else { nameAdd += "认定"; }
            nameAdd += "）";


            string msId = MatchSituationbll.Exists_MatchSituation(stiuid, stiuModel.IsMatch, stiuModel.MatchSource, stiuModel.AffirmIdeaResult, stiuModel.AffirmIdeaSource, allStituationIDs,parentId,1);//存在
            if (msId == "")
            {
                stiuModel.MS_ID = newid.JudgeDoc_CreateID("SYS_Express_MatchSituation");
                msId = stiuModel.MS_ID;
                stiuModel.SituationID = stiuid;
                DataTable dtStiuid = casecausebLL.GetSYS_CaseCauseByCCID(stiuid);
                stiuModel.SituationType = Convert.ToInt32(dtStiuid.Rows[0]["CC_NodeType"]);
                //stiuModel.SituationName = dtStiuid.Rows[0]["CC_Name"] + nameAdd;
                stiuModel.SituationName = stiuidName + nameAdd;
                stiuModel.ParentID = parentId;
                stiuModel.AllStituationIDs = allStituationIDs;
                if (allParentId == "")
                    stiuModel.AllParentID = stiuModel.MS_ID;
                else
                    stiuModel.AllParentID = allParentId + "," + stiuModel.MS_ID;
                stiuModel.CauseGroupID = causeGroupId;
                stiuModel.CC_IsShowExpress = 1;
                MatchSituationbll.AddMatchSituation(stiuModel);//添加
            }
            return msId;

        }


        /// <summary>
        /// 加“组合单一”节点
        /// </summary>
        /// <param name="stiuid">情形节点ID</param>
        /// <param name="situationName">情形节点名</param>
        ///  select  MS_ID  from dbo.SYS_Express_MatchSituation  where SituationID = 'SCCID'  and IsMatch = 0 and MatchSource = '0' and AffirmIdeaSource = '0' and AffirmIdeaResult = '0' and AllStituationIDs = 'SCCID' and ParentID = '0'  and AllParentID = '-1'
        public void AddMatch_virtual(string stiuid, string situationName)
        {
            SYS_Express_MatchSituation stiuModel = new SYS_Express_MatchSituation();
            //判断是否存在条件和添加的条件不一致
            string msId = MatchSituationbll.Exists_MatchSituation(stiuid, 0, "0", "0", "0", stiuid, stiuid, stiuid);//存在
            if (msId == "")
            {

                stiuModel.MS_ID = stiuid;
                stiuModel.SituationID = stiuid;
                stiuModel.SituationType = 9;
                stiuModel.SituationName = situationName;
                stiuModel.ParentID = stiuid;
                stiuModel.AllStituationIDs = stiuid;
                stiuModel.AllParentID = stiuid;
                stiuModel.CauseGroupID = stiuid;

                stiuModel.IsMatch = 0;
                stiuModel.MatchSource = "0";
                stiuModel.AffirmIdeaResult = "0";
                stiuModel.AffirmIdeaSource = "0";
                
                MatchSituationbll.AddMatchSituation(stiuModel);//添加
            }


        }


        /// <summary>
        /// 加“组合单一”节点(民事专用)
        /// </summary>
        /// <param name="stiuid">情形节点ID</param>
        /// <param name="situationName">情形节点名</param>
        public void AddMatch_virtual1(string stiuid, string situationName,string ccId)
        {
            try
            {
                SYS_Express_MatchSituation stiuModel = new SYS_Express_MatchSituation();
                string msId = MatchSituationbll.Exists_MatchSituation1(stiuid, 0, "0", "0", "0", stiuid, ccId);//存在
                if (msId == "")
                {

                    stiuModel.MS_ID = stiuid;
                    stiuModel.SituationID = ccId;
                    stiuModel.SituationType = 9;
                    stiuModel.SituationName = situationName;
                    stiuModel.ParentID = ccId;
                    stiuModel.AllStituationIDs = stiuid;
                    stiuModel.AllParentID = "";
                    stiuModel.CauseGroupID = stiuid;

                    stiuModel.IsMatch = 0;
                    stiuModel.MatchSource = "0";
                    stiuModel.AffirmIdeaResult = "0";
                    stiuModel.AffirmIdeaSource = "0";
                    stiuModel.CC_IsShowExpress = 1;

                    if (!MatchSituationbll.AddMatchSituation(stiuModel))//添加
                    {
                        System.Windows.Forms.MessageBox.Show("添加失败");
                    }
                }
            }
            catch (Exception ex)
            {

                System.Windows.Forms.MessageBox.Show("发生错误："+ex.Message);
            }


        }
        #endregion

        #region 属于哪个匹配表述根节点
        /// <summary>
        /// 属于哪个匹配表述根节点
        /// </summary>
        /// <param name="ccId"></param>
        /// <returns></returns>
        public DataTable BelongCaseCauseId(string ccId,out string caseCauseId)
        {
            //获取节点信息
            DataTable dtStiuid = casecausebLL.GetSYS_CaseCauseByCCID(ccId);

            if (dtStiuid.Rows.Count > 0)
            {
                int ccNodeType = Convert.ToInt32(dtStiuid.Rows[0]["CC_NodeType"]);
                int ccIsProcessNode = Convert.ToInt32(dtStiuid.Rows[0]["CC_IsProcessNode"]);
                //案由
                if (ccNodeType == 2)
                {
                    caseCauseId = ccId;
                    return casecausebLL.GetChildProcessStiuation(ccId);
                }
                else if (ccIsProcessNode == 1)  //匹配表述根节点
                {
                    caseCauseId = casecausebLL.IsParentRealation1(ccId).CC_ID;
                    return dtStiuid;
                }
                else   //普通节点
                {
                    caseCauseId = casecausebLL.IsParentRealation1(ccId).CC_ID;
                    return BelongCaseCauseID_NormalNote(ccId);
                }
            }

            caseCauseId = null;
            return new DataTable();
        }

        public DataTable BelongCaseCauseId(string ccId)
        {
            //获取节点信息
            DataTable dtStiuid = casecausebLL.GetSYS_CaseCauseByCCID(ccId);

            if (dtStiuid.Rows.Count > 0)
            {
                int ccNodeType = Convert.ToInt32(dtStiuid.Rows[0]["CC_NodeType"]);
                int ccIsProcessNode = Convert.ToInt32(dtStiuid.Rows[0]["CC_IsProcessNode"]);
                //案由
                if (ccNodeType == 2)
                {
                    return casecausebLL.GetChildProcessStiuation(ccId);
                }
                else if (ccIsProcessNode == 1)  //匹配表述根节点
                {
                    return dtStiuid;
                }
                else   //普通节点
                {
                    return BelongCaseCauseID_NormalNote(ccId);
                }
            }
            return new DataTable();
        }


        /// <summary>
        /// 属于哪个匹配表述节点(民事)
        /// </summary>
        /// <param name="ccId">ccid</param>
        /// <returns></returns>
        public DataTable CivilBelongCaseCauseId(string ccId)
        {
            //获取节点信息 
            DataTable dtStiuid = BelongCaseCauseID_CivilData(ccId);//casecausebLL.GetSYS_CaseCauseByCCID(ccId);

            //民事不判断CC_IsProcessNode和CC_NodeType属性，直接返回当前查询节点的记录即可  todo by zhangpeng:按照民事最新需求 2017-01-04
            return dtStiuid;

            //if (dtStiuid.Rows.Count > 0)
            //{
            //    int ccNodeType = Convert.ToInt32(dtStiuid.Rows[0]["CC_NodeType"]);
            //    int ccIsProcessNode = Convert.ToInt32(dtStiuid.Rows[0]["CC_IsProcessNode"]);
            //    //案由
            //    if (ccNodeType == 2)
            //    {
            //        return casecausebLL.GetChildProcessStiuation(ccId);
            //    }
            //    else if (ccIsProcessNode == 1)  //匹配表述根节点
            //    {
            //        return dtStiuid;
            //    }
            //    else   //普通节点
            //    {
            //        return BelongCaseCauseID_NormalNote(ccId);
            //    }
            //}
            //return new DataTable();
        }

        #endregion



        #region 获得情形情节分组

        /// <summary>
        /// 普通节点，递归向上级查询，直到上级为情形情节分组（如：犯罪相关情形）
        /// </summary>
        /// <param name="ccId">情形情节ID</param>
        /// <returns></returns>
        public DataTable BelongCaseCauseID_NormalNote(string ccId)
        {
            DataTable dtStiuid = casecausebLL.GetSYS_CaseCauseByCCID(ccId);
            while (dtStiuid.Rows.Count > 0 && Convert.ToInt32(dtStiuid.Rows[0]["CC_IsProcessNode"]) != 1)//不是情形情节分组的节点，向上查
            {
                dtStiuid = casecausebLL.GetSYS_CaseCauseByCCID(dtStiuid.Rows[0]["CC_ParentID"].ToString());
            }

            return dtStiuid;
        }
        #endregion


        public DataTable BelongCaseCauseID_CivilData(string ccId)
        {
            DataTable dtStiuid = casecausebLL.GetSYS_CaseCauseByCCID(ccId);
            while (dtStiuid.Rows.Count > 0)//不是情形情节分组的节点，向上查
            {
                DataTable dtStiuidtemp = casecausebLL.GetSYS_CaseCauseByCCID(dtStiuid.Rows[0]["CC_ParentID"].ToString());
                if (Convert.ToInt32(dtStiuidtemp.Rows[0]["CC_NodeType"]) != 2)
                    dtStiuid = dtStiuidtemp;
                else
                    break;
            }

            return dtStiuid;
        }


        public bool CompareArr(string[] b1, string[] b2)
        {
            if (b1.Length != b2.Length) return false;
            if (b1 == null || b2 == null) return false;
            for (int i = 0; i < b1.Length; i++)
                if (b1[i] != b2[i])
                    return false;
            return true;
        }

        /// <summary>
        /// 排序(A+B+C)
        /// </summary>
        /// <param name="allstiuid">组合情形(A+B+C)</param>
        /// <param name="conditiondt">有顺序的节点集合</param>
        /// <returns>结果</returns>
        public string OrderCC_IDList(string allstiuid, DataTable conditiondt)
        {


            string resultallstiuid = "";

            DataRow[] arrayDR = conditiondt.Select("'," + allstiuid + ",'like '%,'+CC_ID+',%'");
            foreach (var item in arrayDR)
            {
                if (resultallstiuid != "")
                    resultallstiuid += "," + item["CC_ID"];
                else resultallstiuid += item["CC_ID"];
            }

            return resultallstiuid;
        }

    }
}